<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws.
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.).
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations).
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Groups/classes/PhpFox_ComponentNewTopic.class.php, $Author:  $ */



/** Component for Group Forum Posts
 * @version $Id: PhpFox_ComponentNewTopic.class.php
 *  Max Kovrigovich
 * @package module.groups
 */
class PhpFox_Mod_Groups_ComponentNewTopic extends BaseComponent
{
    /** Processing method
     */

    function process()
    {
        //check permissions
        $oSecurityService = App::getModuleService('Account', 'Security');
		/* @var $oSecurityService PhpFox_Mod_Account_ServiceSecurity */
		$oSecurityService->checkPerm('groups', array('full'));

        $oGroupsService = $this->_oModule->getService('Groups');
        /* @var $oGroupsService PhpFox_Mod_Groups_ServiceGroups */

        $oForumService = $this->_oModule->getService('GroupForum');
        /* @var $oForumService PhpFox_Mod_Groups_ServiceGroupForum */

        $oReq = &App::getRequest();
        /* @var $oReq Request */

        $oUrl = &App::getUrl();
        /* @var $oUrl Url */

        $oTpl = $this->_oModule->getTemplate();

        $oUser = $this->getParam('user');
        $iGroupId = $oReq->getInt('id', 0);
        $aGroupData = $oGroupsService->getGroupData($iGroupId);

        $bIsMember = $oGroupsService->isMember($iGroupId, $oUser->aData['user']);

        //check permissions  
        if (!($bIsMember OR App::isStaff() )) 
        {
        	App::gotoUrl('public.groups.private', array('id'=>$iGroupId, 'forum' => 'yes'));
        }
        
        $sTitle = trim($oReq->get('title', 'none'));
        $sText = trim($oReq->get('text', 'none'));
        $sAction = $oReq->getAction();
        if($sAction == 'submit')
        {
            $iTopicId = $oForumService->addTopic(
            array(
                'group_id'=>$iGroupId,
                'user'=>$oUser->aData['user'],
                'title'=>$sTitle,
                'text'=>$sText,
                'time'=>time(),
                'type'=>'',
                'views'=>'0',));
            App::gotoUrl('public.groups.forum.posts', array('id'=>$iTopicId));
        }

        $oTpl->assign(array(
        	'aGroupData' => $aGroupData,
	        'sFormUrl' => $oUrl->getUrl(),
	        'aFormHidden' => array('act'=>'submit'),
        ));

        $sHtml = $oTpl->fetch('NewTopic.html');
        return $sHtml;
    }
}
?>